MediaSource 路 WebPlatform Docs

您所在的位置:网站首页 web mediaSource MediaSource 路 WebPlatform Docs

MediaSource 路 WebPlatform Docs

2024-03-23 10:50| 来源: 网络整理| 查看: 265

MediaSource Summary

Represents a source of media data (audio or video) for a media element.

Overview

Provides a buffer based source for a media object. The app creates a MediaSource object and adds it to the media (audio or video) object as a source for the src object. SourceBuffers are then added to the MediaSource object and media content is then appended to the buffers to provide streaming or multi-source playback.

var mediaSource = new MediaSource();

Properties

No properties.

Methods addSourceBuffer Creates a new SourceBuffer and adds it to the SourceBuffers property of the MediaSource. appendBuffer Appends the specified media segment to the SourceBuffer. endOfStream Used to indicate that the end of the stream has been reached. Events

No events.

Examples

This example creates a new MediaSource object and adds it to a video object. It then adds a sourceBuffer and calls to start loading content.

The live sample only runs on a browser that support the W3C syntax and MP4 files.

// Create mediaSource and initialize video function setupVideo() { // Create the media source if (window.MediaSource) { mediaSource = new window.MediaSource(); } else { log("mediasource or syntax not supported"); return; } var url = URL.createObjectURL(mediaSource); videoElement.src = url; // Wait for event that tells us that our media source object is // ready for a buffer to be added. mediaSource.addEventListener('sourceopen', function (e) { try { videoSource = mediaSource.addSourceBuffer('video/mp4'); // initialize and start loading segments of video } catch (e) { // error reporting here return; } }); }

View live example

Related specifications Media Source Extensions W3C Candidate Recommendation See also Related articles Multimedia

Track ended

MediaSource

appendBuffer

WebRTC

object-fit

height

standby

EMBED

img

WebRTC Resources

}

}

Attributions

Microsoft Developer Network.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3